//
//  AllCompentViewController.m
//  u76ho
//
//  Created by m-air-01 on 16/1/6.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "AllCompentViewController.h"
#import "InServeiCompanyFirCell.h"
#import "AllcommendModel.h"
#import "BoostViewController.h"
@interface AllCompentViewController ()
<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,UIAlertViewDelegate,UINavigationBarDelegate>
{
    UITableView * _tabelView;
    
    AllcommendModel * myModel;
    NSMutableArray * dataSource;
    
}
@end

@implementation AllCompentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    [self createCommendView];
    
    [self addBackItem];
    
    self.navigationItem.title = @"个人动态";
    
   // [self addNavgationBarWithtitle:@"个人动态"];
    [self registerForKeyboardNotifications];
    // Do any additional setup after loading the view.
}

#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
    
    
    
}


-(void)backItem:(id)sender
{
        
    if (_isAPNS) {
        AppDelegate * app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        self.view.window.rootViewController = app.viewController;
    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

-(void)main
{
    dataSource = [[NSMutableArray alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    _tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 49 - 64) style:UITableViewStyleGrouped];
    _tabelView.delegate = self;
    _tabelView.dataSource = self;
    [_tabelView registerNib:[UINib nibWithNibName:@"InServeiCompanyFirCell" bundle:nil] forCellReuseIdentifier:@"InServeiCompanyFirCell"];
    [self.view addSubview:_tabelView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self requestData];
}
-(void)requestData
{
    [U76HONet infomationDetailWithAction:@"" infoid:_infoId andDataBlock:^(AllcommendModel *model) {
        NSLog(@"全部评论获取信息成功列");
        _dynaOneModel.dynaCommendmodelArr = model.commendContentArr;
        _dynaOneModel.baseInfomodel.discuss = model.baseInfomodel.discuss;
        if (!_isAPNS) {
            _refreshBlock(_dynaOneModel);
        }
        myModel = model;
        if (dataSource.count!=0) {
            [dataSource removeAllObjects];
        }
        if (model.commendContentArr != nil) {
            [dataSource addObjectsFromArray:model.commendContentArr];
        }
        [_tabelView reloadData];
    }];
}
-(void)sendCommendWithContent:(NSString *)content
{
    __weak typeof(self)weakSelf = self;
    [U76HONet sendCommendWitnAction:@"" code:[Singleton share].code Msgid:_infoId Content:content andDataBlock:^(NSDictionary *dic) {
        NSLog(@"发表评论数据成了");
        [weakSelf requestData];
        UITextView * textView = (UITextView *)[weakSelf.view viewWithTag:712];
        textView.text = @"";
//        _refreshBlock();
    }];
}
-(void)zanortuWithType:(NSString *)type andTag:(int)tag
{
    if ([self isLogin]) {
        [U76HONet tuZanWitnAction:@"" code:[Singleton share].code Msgid:_infoId Opinion:type andDataBlock:^(NSDictionary *dic) {
            
            UIButton * btn = (UIButton *)[self.view viewWithTag:tag];
            
            NSString * str = btn.titleLabel.text;
            //        NSString * str = btn.titleLabel.text;
            
            NSArray * arr = [str componentsSeparatedByString:@" "];
            NSString * tempStr = arr.lastObject;
            int i = [tempStr intValue];
            
            if ([type isEqualToString:@"1"]) {
                _dynaOneModel.baseInfomodel.praise = [NSString stringWithFormat:@" %i",i+1];
            }
            else
            {
                _dynaOneModel.baseInfomodel.vomit = [NSString stringWithFormat:@" %i",i+1];
            }
            _refreshBlock(_dynaOneModel);
            
            [btn setTitle:[NSString stringWithFormat:@" %i",i+1] forState:UIControlStateNormal];
            
            
            NSLog(@"图赞成功列");
        }];
    }
    
}
#pragma mark - _tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    InServeiCompanyFirCell * cell = [tableView dequeueReusableCellWithIdentifier:@"InServeiCompanyFirCell"];
    InServeiCompanyFirCell * cell = [tableView dequeueReusableCellWithIdentifier:@"InServeiCompanyFirCell" forIndexPath:indexPath];

    cell.commendInfomodel = dataSource[indexPath.row];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return  [self createSectionView];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    AllCommendBaseInfoModel * baseInfomodel = myModel.baseInfomodel;
    //动态内容
    NSString * contentStr ;
    
//    NSAttributedString * Str = [[NSAttributedString alloc] initWithData:[baseInfomodel.content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    contentStr = baseInfomodel.content;
    CGFloat height = [contentStr heightOfSize:20 width:SCREEN_WIDTH-30];

    int j = 0;
    //动态中发表的图片
    CGFloat tempHeight;
    if (![baseInfomodel.pic isEqualToString:@""]) {
        
        CGFloat imgVwidth = (SCREEN_WIDTH - SIZETO6W(15)*2 - SIZETO6W(10)*2) / 3;
        
        NSArray * imgUrlArr = [baseInfomodel.pic componentsSeparatedByString:@"|"];
        
        for (int i = 0; i<imgUrlArr.count; i++) {
            
            int row=i/3;//行号
            j = row;
        }
        tempHeight = imgVwidth + j* (imgVwidth+SIZETO6W(10));

    }
    else
    {
        tempHeight = 0;
    }

    
    
    
    if (myModel.zanArr.count!=0) {
//        tempHeight += 40;
        CGFloat zanheigt = 0;
        NSArray * zanArr = [[NSMutableArray alloc]initWithArray:myModel.zanArr];
        
        NSMutableString * mStr = [[NSMutableString alloc]init];
        for (int i = 0; i<zanArr.count; i++) {
            AllZanModel * mod = [zanArr objectAtIndex:i];
            if (i == 0) {
                [mStr appendString:mod.username];
            }
            else
            {
                [mStr appendString:[NSString stringWithFormat:@",%@",mod.username]];
            }
        }
        zanheigt = [mStr heightOfSize:20 width:SCREEN_WIDTH - 30] + 5;
        tempHeight +=zanheigt;
        
    }

    return 130+tempHeight + height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AllCommendInfoModel * model = dataSource[indexPath.row];
    CGFloat tempHeight = [model.content heightOfSize:17 width:(SCREEN_WIDTH - 53 - SIZETO6W(15))];
    return tempHeight + 30+10;
}
#pragma mark - createSectionView
-(UIView *)createSectionView
{
    if (myModel != nil) {
        
        AllCommendBaseInfoModel * baseInfomodel = myModel.baseInfomodel;
        
        UIView * sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 170+(SCREEN_WIDTH-30)/3)];
        sectionView.backgroundColor = [UIColor whiteColor];
        
        //头像
        UIImageView * headerImgV = [[UIImageView alloc]initWithFrame:CGRectMake(SIZETO6W(15), 15, 40, 40)];
        headerImgV.layer.masksToBounds = YES;
        headerImgV.layer.cornerRadius = 20;
        [headerImgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",U76HOURL,baseInfomodel.headpic]] placeholderImage:[UIImage imageNamed:@"公司简介成长－默认头像"]];
        [sectionView addSubview:headerImgV];

        
        //用户名
        UILabel * nameLab = [[UILabel alloc]initWithFrame:CGRectMake(headerImgV.right+SIZETO6W(10), 15, 100, 20)];
        nameLab.text = baseInfomodel.username;
        nameLab.font = [UIFont systemFontOfSize:15];
        nameLab.textColor = UIColorFromRGB(0x333944);
        [sectionView addSubview:nameLab];
        //时间label
        
        UILabel * dateLab = [[UILabel alloc]initWithFrame:CGRectMake(headerImgV.right+SIZETO6W(10), nameLab.bottom, 150, 20)];
//        //时间
//        NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
//        formatter.dateFormat = @"yyyy-MM-dd";
//        NSString * dataCh = baseInfomodel.addtime;
//        NSString * dataStr = [dataCh substringToIndex:dataCh.length];
//        NSDate * data = [[NSDate dateWithTimeIntervalSince1970:[dataStr integerValue]] dateByAddingTimeInterval:8*3600];
//        NSString * lastStr = [NSString stringWithFormat:@"%@",data];
//        NSArray * lastArr = [lastStr componentsSeparatedByString:@" "];
//        dateLab.text = lastArr[0];
//        
//        dateLab.font = [UIFont systemFontOfSize:15];
//        dateLab.textColor = UIColorFromRGB(0x94999F);
//        [sectionView addSubview:dateLab];
        
        //时间
        NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        NSString * dataCh = baseInfomodel.addtime;
        NSString * dataStr = [dataCh substringToIndex:dataCh.length];
        NSDate * data = [[NSDate dateWithTimeIntervalSince1970:[dataStr integerValue]] dateByAddingTimeInterval:8*3600];
        NSString * lastStr = [NSString stringWithFormat:@"%@",data];
        NSArray * lastArr = [lastStr componentsSeparatedByString:@" "];
        NSMutableArray * mArr = [[NSMutableArray alloc]init];
        for (int i = 0; i<2; i++) {
            [mArr addObject:lastArr[i]];
        }
        dateLab.text = [mArr componentsJoinedByString:@" "];
        
        dateLab.font = [UIFont systemFontOfSize:15];
        dateLab.textColor = UIColorFromRGB(0x94999F);
        [sectionView addSubview:dateLab];

        
        //动态内容
        NSString * contentStr;
        
//        NSAttributedString * Str = [[NSAttributedString alloc] initWithData:[baseInfomodel.content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
//        contentStr = [Str string];
        contentStr = baseInfomodel.content;
        CGFloat height = [contentStr heightOfSize:17 width:SCREEN_WIDTH-30];
        
        UILabel * contentLab = [[UILabel alloc]initWithFrame:CGRectMake(SIZETO6W(15), dateLab.bottom+SIZETO6H(15), SCREEN_WIDTH-30, height)];
        contentLab.text = contentStr;
        contentLab.numberOfLines = 0;
        contentLab.textColor = UIColorFromRGB(0x333944);
        [sectionView addSubview:contentLab];
        
        //动态中发表的图片
        int j = 0;
        CGFloat tempHeight;
        if (![baseInfomodel.pic isEqualToString:@""]) {
            CGFloat imgVwidth = (SCREEN_WIDTH - SIZETO6W(15)*2 - SIZETO6W(10)*2) / 3;
            NSRange range = [baseInfomodel.pic rangeOfString:@"|"];
            if (range.location != NSNotFound) {
                NSArray * imgUrlArr = [baseInfomodel.pic componentsSeparatedByString:@"|"];
                
                
                for (int i = 0; i<imgUrlArr.count; i++) {
                    
                    int row=i/3;//行号
                    int loc=i%3;//列号
                    j = row;
                    UIImageView * imgV = [[UIImageView alloc]initWithFrame:CGRectMake(SIZETO6W(15) + loc * (imgVwidth+SIZETO6W(10)), contentLab.bottom + row*(SIZETO6W(10) + imgVwidth), imgVwidth, imgVwidth)];
                    imgV.userInteractionEnabled = YES;
                    [imgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",U76HOURL,imgUrlArr[i]]] placeholderImage:[UIImage imageNamed:@"在职公司－默认动态图"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        
                        
                        
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            float tempW = (image.size.height - image.size.width) >= 0 ? image.size.width : image.size.height;
                            imgV.image = [image croppedImageAtFrame:CGRectMake((image.size.height - image.size.width) >= 0 ? 0 : (image.size.width - image.size.height)/2, (image.size.width - image.size.height) >= 0 ? 0 : (image.size.height - image.size.width)/2 , tempW, tempW)];
                        });
                        
                        
                    }];
                    //点击手势
                    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction2:)];
                    tap.numberOfTapsRequired = 1;
                    tap.numberOfTouchesRequired = 1;
                    imgV.tag = i+1;
                    
                    [imgV addGestureRecognizer:tap];
                    [sectionView addSubview:imgV];
                    
                }

            }
            else
            {
                UIImageView * imgV = [[UIImageView alloc]initWithFrame:CGRectMake(SIZETO6W(15), contentLab.bottom, imgVwidth, imgVwidth)];
                [imgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",U76HOURL,baseInfomodel.pic]] placeholderImage:[UIImage imageNamed:@"在职公司－默认动态图"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                    
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        float tempW = (image.size.height - image.size.width) >= 0 ? image.size.width : image.size.height;
                        imgV.image = [image croppedImageAtFrame:CGRectMake((image.size.height - image.size.width) >= 0 ? 0 : (image.size.width - image.size.height)/2, (image.size.width - image.size.height) >= 0 ? 0 : (image.size.height - image.size.width)/2 , tempW, tempW)];
                    });
                    
                }];
                imgV.userInteractionEnabled = YES;
                //点击手势
                UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction2:)];
                tap.numberOfTapsRequired = 1;
                tap.numberOfTouchesRequired = 1;
                imgV.tag = 1;
                [imgV addGestureRecognizer:tap];
                [sectionView addSubview:imgV];
                

            }
            tempHeight = imgVwidth + j* (imgVwidth+SIZETO6W(10));

        }
        else
        {
            tempHeight = 0;
        }
        
        UIButton * zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        zanBtn.frame = CGRectMake(SIZETO6W(15), contentLab.bottom+SIZETO6H(10) + SIZETO6W(5) + tempHeight, 60, 30);
        [zanBtn setImage:[UIImage imageNamed:@"点赞"] forState:UIControlStateNormal];
        [zanBtn setTitle:baseInfomodel.praise forState:UIControlStateNormal];
        [zanBtn setTitleColor:UIColorFromRGB(0x333944) forState:UIControlStateNormal];
        [zanBtn setBackgroundColor:UIColorFromRGB(0xEDF0EF)];
        
        zanBtn.layer.masksToBounds = YES;
        zanBtn.tag = 100;
        zanBtn.layer.cornerRadius = 5;
        [zanBtn addTarget:self action:@selector(zanBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [sectionView addSubview:zanBtn];
        
        UIButton * tuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        tuBtn.frame = CGRectMake(zanBtn.right+SIZETO5W(10), zanBtn.top, 60, 30);
        [tuBtn setBackgroundColor:UIColorFromRGB(0xEDF0EF)];
        [tuBtn setImage:[UIImage imageNamed:@"吐"] forState:UIControlStateNormal];
        [tuBtn setTitle:[NSString stringWithFormat:@" %@",baseInfomodel.vomit] forState:UIControlStateNormal];
        [tuBtn addTarget:self action:@selector(tuAction:) forControlEvents:UIControlEventTouchUpInside];
        [tuBtn setTitleColor:UIColorFromRGB(0x333944) forState:UIControlStateNormal];
        tuBtn.layer.masksToBounds = YES;
        tuBtn.tag = 101;
        tuBtn.layer.cornerRadius = 5;
        [sectionView addSubview:tuBtn];

        
        
        UIButton * pinglunBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        pinglunBtn.frame = CGRectMake(tuBtn.right+SIZETO5W(10), zanBtn.top, 60, 30);
        [pinglunBtn setBackgroundColor:UIColorFromRGB(0xEDF0EF)];
        [pinglunBtn setImage:[UIImage imageNamed:@"评论"] forState:UIControlStateNormal];
        [pinglunBtn setTitle:[NSString stringWithFormat:@" %@",baseInfomodel.discuss] forState:UIControlStateNormal];
        [pinglunBtn setTitleColor:UIColorFromRGB(0x333944) forState:UIControlStateNormal];
        pinglunBtn.layer.masksToBounds = YES;
        pinglunBtn.layer.cornerRadius = 5;
        [sectionView addSubview:pinglunBtn];
        
        CGFloat zanHeigt = 0;
        if (myModel.zanArr.count!=0) {
            NSArray * zanArr = myModel.zanArr;
            UIImageView * imgV = [[UIImageView alloc]initWithFrame:CGRectMake(zanBtn.left, zanBtn.bottom + 15, 20, 20)];
            imgV.image = [UIImage imageNamed:@"点赞"];
            [sectionView addSubview:imgV];
            
            //点赞人物
            UILabel * zanPeopleLab = [[UILabel alloc]initWithFrame:CGRectMake(imgV.right+5, imgV.top+5, 250, 20)];
            
            
            NSMutableString * mStr = [[NSMutableString alloc]init];
            for (int i = 0; i<zanArr.count; i++) {
                AllZanModel * mod = [zanArr objectAtIndex:i];
                if (i == 0) {
                    [mStr appendString:mod.username];
                }
                else
                {
                    [mStr appendString:[NSString stringWithFormat:@",%@",mod.username]];
                }
            }
            zanHeigt = [mStr heightOfSize:17 width:SCREEN_WIDTH - 30] + 5;
            
            
            zanPeopleLab.text = mStr;
            zanPeopleLab.numberOfLines = 0;
            zanPeopleLab.frame = CGRectMake(imgV.right+5, imgV.top, SCREEN_WIDTH-25, zanHeigt);
            [sectionView addSubview:zanPeopleLab];
        }
        
        sectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 130+tempHeight+height-20+zanHeigt);
        return sectionView;

    }
    return nil;
}
-(void)tapAction2:(UITapGestureRecognizer *)tap
{
    NSLog(@"tapAction is did");
    int tag = (int)tap.view.tag;
    if (myModel.baseInfomodel!=nil) {
        if (![myModel.baseInfomodel.pic isEqualToString:@""]) {
            NSArray * imgUrlArr = [myModel.baseInfomodel.pic componentsSeparatedByString:@"|"];
            BoostViewController * boostVC = [[BoostViewController alloc]init];
            boostVC.imgArr = imgUrlArr;
            boostVC.contentStr = myModel.baseInfomodel.content;
            boostVC.i = tag;
            [self.navigationController pushViewController:boostVC animated:YES];
        }
    }
    
}

#pragma mark - createCommendView
-(void)createCommendView
{
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-49, SCREEN_WIDTH, 49)];
    view.backgroundColor = [UIColor whiteColor];
    view.tag = 504;
    view.userInteractionEnabled = YES;
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(SCREEN_WIDTH-SIZETO6W(15)-50, 0, 50, 49);
    [rightBtn setTitle:@"发送" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(sendCommendAction:) forControlEvents:UIControlEventTouchUpInside];

    [rightBtn setTitleColor:UIColorFromRGB(0x333944) forState:UIControlStateNormal];
    [view addSubview:rightBtn];
    
    UIView * subView = [[UIView alloc]initWithFrame:CGRectMake(SIZETO6W(15), SIZETO6H(6), SCREEN_WIDTH-SIZETO6W(15)*2-50, view.height-SIZETO6H(6)*2)];
    subView.backgroundColor = [UIColor lightGrayColor];
    subView.layer.masksToBounds = YES;
    subView.layer.cornerRadius = 20;
    subView.userInteractionEnabled = YES;
    [view addSubview:subView];
    
    
    
    UITextView * textView = [[UITextView alloc]initWithFrame:CGRectMake(SIZETO6W(15), 0, subView.width-SIZETO6W(15)*2, subView.height)];
    textView.backgroundColor = [UIColor lightGrayColor];
    textView.delegate =self;
    textView.font = [UIFont systemFontOfSize:16];
//    textView.keyboardType = UIKeyboardTypeAlphabet;
    textView.tag = 712;
    [subView addSubview:textView];
    
    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(22, subView.height/2-10, 150, 20)];
    lab.tag = 506;
    lab.textColor = [UIColor whiteColor];
    lab.text = @"评论点什么吧";
    [subView addSubview:lab];
    
    [self.view addSubview:view];
    
}
#pragma mark - 按钮们的点击事件
-(void)sendCommendAction:(UIButton *)btn
{
    NSLog(@"sendBtn is selected");
    
    UITextView * textView = (UITextView *)[self.view viewWithTag:712];
    NSString * s = textView.text;
    
    if ([self isEmpty:s]) {
        textView.text = @"";
        UILabel * lab = (UILabel *)[self.view viewWithTag:506];
        
        if ([textView.text isEqualToString:@""]) {
            if (lab.hidden == YES) {
                lab.hidden = NO;
            }
        }
        return ;
    }
    
    NSString * emjStr = textView.text;
    [emjStr enumerateSubstringsInRange:NSMakeRange(0, emjStr.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
        if (substring.length == 2) {
            NSLog(@"******%@",substring);
            textView.text = @"";
            UILabel * lab = (UILabel *)[self.view viewWithTag:506];
            if (lab.hidden == YES) {
                lab.hidden = NO;
            }
            [Singleton alerSendMessage:@"暂不支持表情符号"];
            return ;
        }
    }];
    
    if ([self isLogin]) {
        [self.view endEditing:YES];
        //销毁蒙板
        UIView * mengBanView = (UIView *)[self.view viewWithTag:505];
        [mengBanView removeFromSuperview];
        
        UITextView * textView = (UITextView *)[self.view viewWithTag:712];
        if (![textView.text isEqualToString:@""]) {
            [self sendCommendWithContent:textView.text];
        }
    }
    
}
-(BOOL) isEmpty:(NSString *) str {
    
    if (!str) {
        return true;
    } else {
        //A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        
        //Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];
        
        if ([trimedString length] == 0) {
            return true;
        } else {
            return false;
        }
    }
}

-(void)zanBtnAction:(UIButton *)btn
{
//    NSString * str = btn.titleLabel.text;
//    NSArray * arr = [str componentsSeparatedByString:@" "];
//    NSString * tempStr = arr.lastObject;
//    int i = [tempStr intValue];
//    [btn setTitle:[NSString stringWithFormat:@" %i",i+1] forState:UIControlStateNormal];
    
    //调用图赞接口
    [self zanortuWithType:@"1" andTag:(int)btn.tag];
}
-(void)tuAction:(UIButton *)btn
{
//    NSString * str = btn.titleLabel.text;
//    NSArray * arr = [str componentsSeparatedByString:@" "];
//    NSString * tempStr = arr.lastObject;
//    int i = [tempStr intValue];
//    [btn setTitle:[NSString stringWithFormat:@" %i",i+1] forState:UIControlStateNormal];

    //调用图赞接口
    [self zanortuWithType:@"2" andTag:(int)btn.tag];
}
-(BOOL)isLogin
{
    if ([Singleton share].code) {
        NSLog(@"登录了");
        return YES;
        
    }
    else
    {
        //        NSLog(@"还没登录呢");
        //        LoginViewController * loginVC = [[LoginViewController alloc]init];
        //        [self.navigationController pushViewController:loginVC animated:NO];
        //        return NO;
        if (SYSTEM_VERSION >= 8.0) {
            UIAlertController * alerVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有登录是否登录" preferredStyle:UIAlertControllerStyleAlert];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                
                LoginViewController * loginVC = [[LoginViewController alloc]init];
                UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:loginVC];
                nvc.navigationBarHidden = YES;
                
                [self presentViewController:nvc animated:YES completion:nil];
                
            }]];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                
            }]];
            [self.view.window.rootViewController presentViewController:alerVC animated:YES completion:nil];
            
        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您还没有登录是否登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }
        return NO;
        
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    int i = (int)buttonIndex;
    if (i == 0) {
        
    }
    else if(i == 1)
    {
        LoginViewController * loginVC = [[LoginViewController alloc]init];
        UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:loginVC];
        nvc.navigationBarHidden = YES;
        
        [self presentViewController:nvc animated:YES completion:nil];
    }
}
#pragma mark - UITextViewDelegate
//-(void)textViewDidBeginEditing:(UITextView *)textView
//{
//    UILabel * lab = (UILabel *)[self.view viewWithTag:506];
//    if (lab.hidden == NO) {
//        lab.hidden = YES;
//    }
//}
-(void)textViewDidChange:(UITextView *)textView
{
    UILabel * lab = (UILabel *)[self.view viewWithTag:506];

    if ([textView.text isEqualToString:@""]) {
        if (lab.hidden == YES) {
            lab.hidden = NO;
        }
    }
    else
    {
        lab.hidden = YES;
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
    UILabel * lab = (UILabel *)[self.view viewWithTag:506];
    
    if ([textView.text isEqualToString:@""]) {
        if (lab.hidden == YES) {
            lab.hidden = NO;
        }
    }

}

#pragma mark - 获取键盘动态高度
- (void) registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];
    
}
- (void) keyboardWasShown:(NSNotification *) notif
{
    
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    
    NSLog(@"***************keyBoard:%f", keyboardSize.height);  //216
    ///keyboardWasShown = YES;
    
    UIView * view = (UIView *)[self.view viewWithTag:504];
    // 获取键盘动画时间
    CGFloat animationTime  = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    // 定义好动作
    void (^animation)(void) = ^void(void) {
        view.transform = CGAffineTransformMakeTranslation(0, - keyboardSize.height);
    };
    
    if (animationTime > 0) {
        [UIView animateWithDuration:animationTime animations:animation];
    } else {
        animation();
    }
    
    //创建蒙板
    UIView * mengBanView = (UIView *)[self.view viewWithTag:505];
    if (mengBanView) {
        [UIView animateWithDuration:0.001 animations:^{
            mengBanView.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64-keyboardSize.height - 49);
            mengBanView.alpha = 0.1;
            [self.view addSubview:mengBanView];
            
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            tap.numberOfTapsRequired = 1;
            tap.numberOfTouchesRequired = 1;
            [mengBanView addGestureRecognizer:tap];
            
        } completion:^(BOOL finished) {
            
        }];

    }
    else
    {
        [UIView animateWithDuration:0.001 animations:^{
            UIView * mengBanView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64-keyboardSize.height - 49)];
            mengBanView.tag = 505;
            mengBanView.alpha = 0.1;
            [self.view addSubview:mengBanView];
            
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            tap.numberOfTapsRequired = 1;
            tap.numberOfTouchesRequired = 1;
            [mengBanView addGestureRecognizer:tap];
            
        } completion:^(BOOL finished) {
            
        }];

    }

    
}
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    [self.view endEditing:YES];
    [tap.view removeFromSuperview];
}

- (void) keyboardWasHidden:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height);
    // keyboardWasShown = NO;
    
    UIView * view = (UIView *)[self.view viewWithTag:504];
    CGFloat animationTime  = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    // 定义好动作
    void (^animation)(void) = ^void(void) {
        view.transform = CGAffineTransformIdentity;
    };
    
    if (animationTime > 0) {
        [UIView animateWithDuration:animationTime animations:animation];
    } else {
        animation();
    }
    //销毁蒙板
    UIView * mengBanView = (UIView *)[self.view viewWithTag:505];
    [mengBanView removeFromSuperview];
}
//#pragma mark - NAVgationBarTitle
//-(void)addNavgationBarWithtitle:(NSString *)title
//{
//    UILabel * titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, 30)];
//    titleLab.textAlignment = NSTextAlignmentCenter;
//    titleLab.text = title;
//    self.navigationItem.titleView = titleLab;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
